import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Date;

public class DateDifferenceCalculator {

    public static long getDaysBetweenDates(Date vipStartTime, Date vipEndTime) {
        // 定义时区，这里使用默认时区
        ZoneId zone = ZoneId.systemDefault();

        // 将Date转换为Instant，再转换为ZonedDateTime，最后提取LocalDate
        LocalDate start = vipStartTime.toInstant().atZone(zone).toLocalDate();
        LocalDate end = vipEndTime.toInstant().atZone(zone).toLocalDate();

        // 计算两个日期之间的天数差
        long days = ChronoUnit.DAYS.between(start, end);

        // 如果需要包含结束日期，加1
        // long days = ChronoUnit.DAYS.between(start, end) + 1;

        return days;
    }

    public static int differentDaysByMillisecond(Date date1, Date date2) {
        return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24)));
    }

    public static String getDatePoor(Date endDate, Date nowDate) {
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        // long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
        long hour = diff % nd / nh;
        // 计算差多少分钟
        long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
        // long sec = diff % nd % nh % nm / ns;
        return day + "天" + hour + "小时" + min + "分钟";
    }

    public static void main(String[] args) {
        // 示例日期
        Date vipStartTime = new Date();
        Date vipEndTime = new Date(vipStartTime.getTime() + 3 * 24 * 60 * 60 * 1000); // 3天后
        long days = getDaysBetweenDates(vipStartTime, vipEndTime);
        System.out.println("两个日期之间的天数差: " + days);
        System.out.println(differentDaysByMillisecond(vipStartTime, vipEndTime));
        System.out.println(getDatePoor(vipEndTime, new Date()));
    }
}